<?php

declare (strict_types = 1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://doc.hyperf.io
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
 */

namespace HyperfTest\Cases;

use HyperfTest\HttpTestCase;

/**
 * @internal
 * @coversNothing
 */
class UserTest extends HttpTestCase {
    public function testRegist() {
        $rt = $this->post('/regist', [
            'account' => 'account',
            'password' => '1',
        ]);
        var_dump($rt);
        echo "测试账号重复";
        $this->assertTrue($rt['code'] == 100000);
    }
    public function testLogin() {
        echo "测试登录 失败";
        $rt = $this->post('/login', [
            'account' => 'account',
            'password' => 'not this pw',
        ]);
        $this->assertTrue($rt['code'] !== 0);

        echo "测试登录 成功";
        $rt = $this->post('/login', [
            'account' => 'account',
            'password' => '1',
        ]);
        $this->assertTrue($rt['code'] !== 0);
    }
    public function testGetInfo() {
        $rt = $this->post('/login', [
            'account' => 'account',
            'password' => '1',
        ]);
        $token = $rt['data']['token'];
        $rt = $this->get('/my', [], [
            'Authorization' => "Bearer {$token}",
        ]);
        $this->assertTrue($rt['data']['account'] == 'account');
    }
}
